import ParentHook from '../Hook.js';
import FormOperation from './FormOperation.js';

let index = 1;
// Hook为基础库的架构的核心，可作为数据载体
// Hook上默认配置仅限于area的构造
class Hook extends ParentHook {
	constructor(...args) {
		super(...args);
		this.uiName = 'antd';
		this.optionsValueField = 'value';
	}
	hookFormItem(...args) {
		return this.initFormItem('name', ...args);
	}
	hookFormParam(area, param) {
		return {
			ref: v => area.formOper = new FormOperation(area, v),
			initialValues: area.nameManger.values,
			...param
		};
	}
	hookInitValues(nameManger) {
		const { initialValues, staticValues } = nameManger;
		return { ...staticValues, ...initialValues };
	}
	hookItemCall(buildItem) {
		const { groupConfig, defaultValue } = this.initValue(buildItem);
		const { $name, ...o } = buildItem.info;
		// 目前仅针对vue环境初始化基础参数
		if ($name) {
			// 根据$name参数，解析得到临时的name字符串
			o.name = buildItem.area.nameManger.input($name, { defaultValue });
		}
		// 下拉框，单选框，复选框
		return groupConfig ? this.initGroup(buildItem, groupConfig, o) : o;
	}
	// ----------------------------------------------------------
	hookBuildRule(msg, callback) {
		return msg ? Promise.reject(msg) : null;
	}
	hookGetOptionsSelect(cb1, text, key) {
		cb1(param => param.key = key);
		return text;
	}
	hookRadioButton(param) {
		param.buttonStyle = 'solid';
	}
	hookDialog(show) {
		return {
			open: true,
			onCancel: () => show.value = false,
		};
	}
}
export default Hook;